package com.jindi.appuser.common;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: duanj
 * Date: 2017-12-22
 * Time: 15:48
 * Description:
 */
public class PlanUtil {

    /**
     * 判断龙虎玩法是否中奖
     *
     * @param num1
     * @param num2   （例：玩法:【万个龙虎】，开奖号码【1,3,5,6,4】；【num1】就为开奖号码的万位的号码【1】，【num2】就为个位的号码【4】）
     * @param number 预测的值。【龙，虎，合】
     * @return
     */
    public static boolean longHu(Integer num1, Integer num2, String number) {
        if (num1 == num2 && "合".equals(number.trim())) {
            return true;
        }
        if (num1 != num2 && (num1 > num2 ? "龙" : "虎").equals(number)) {
            return true;
        }
        return false;
    }

    public static StringBuffer randomCommon(int min, int max, int n){
        StringBuffer sb = new StringBuffer();
        if (n > (max - min + 1) || max < min) {
            return null;
        }
        int[] result = new int[n];
        for (int i=0;i<result.length;i++){
            result[i]=11;
        }
        int count = 0;
        while(count < n) {
            int num = (int) (Math.random() * (max - min)) + min;
            boolean flag = true;
            for (int j = 0; j < n; j++) {
                if(num == result[j]){
                    flag = false;
                    /*if(num == result[j] && num == 0){
                        flag = true;
                    }*/
                    break;
                }
            }
            if(flag){
                result[count] = num;
                count++;
            }
        }
        Arrays.sort(result);
        for (int a :result) {
            sb.append(a+",");
        }
        sb.deleteCharAt(sb.length()-1);
        return sb;
    }


    //前二单式
    public static Set getTwoDan(Integer number){
        //qqList<Integer> list = new ArrayList<Integer>();
        Set<String> list1 = new TreeSet<String>();
        Random rand = new Random();

        List<String> list = new ArrayList();
        for (int i=0;i<10;i++) {
            for (int j=0;j<10;j++) {
                StringBuffer stringBuffer = new StringBuffer(3);
                stringBuffer.append(i);
                stringBuffer.append(j);
                list.add(stringBuffer.toString());
            }
        }
        while(list1.size() < number)
        {
            list1.add(list.get(rand.nextInt(list.size())));
        }
        Arrays.sort(list1.toArray());
        return list1;
    }

    //前三单式
    public static Set getThreeDan(Integer number){
        //qqList<Integer> list = new ArrayList<Integer>();
        Set<String> list1 = new TreeSet<String>();
        Random rand = new Random();

        List<String> list = new ArrayList();
        for (int i=0;i<10;i++) {
            for (int j=0;j<10;j++) {
                for (int k=0;k<10;k++) {
                    StringBuffer stringBuffer = new StringBuffer(3);
                    stringBuffer.append(i);
                    stringBuffer.append(j);
                    stringBuffer.append(k);
                    list.add(stringBuffer.toString());
                }
            }
        }
        while(list1.size() < number)
        {
            list1.add(list.get(rand.nextInt(list.size())));
        }
        Arrays.sort(list1.toArray());
        return list1;
    }
}
